// Copyright (c) 2025 Zhou Yiyan
// Dynamic World Generation Library is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

// Example demonstrating difficulty-based terrain generation.
package main

import (
	"fmt"
	"log"

	"gitee.com/sweetiron/world-gen"
)

func main() {
	seed := int64(54321)
	generator := worldgen.NewNoiseGenerator(seed)

	// Generate chunks with different difficulty levels
	difficulties := []float64{0.1, 0.5, 0.9}

	for _, difficulty := range difficulties {
		chunk, err := generator.GenerateChunk(worldgen.ChunkCoord{X: 0, Y: 0},
			difficulty, 0.0, nil) // No similarity
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("\nDifficulty: %.1f\n", difficulty)
		printTerrainDistribution(chunk)
	}
}

// printTerrainDistribution shows the percentage of each terrain type.
func printTerrainDistribution(chunk worldgen.ChunkData) {
	counts := make(map[worldgen.TileType]int)
	total := worldgen.ChunkSize * worldgen.ChunkSize

	for y := 0; y < worldgen.ChunkSize; y++ {
		for x := 0; x < worldgen.ChunkSize; x++ {
			counts[chunk[y][x]]++
		}
	}

	fmt.Println("Terrain distribution:")
	for tileType := worldgen.TileTypeEmpty; tileType <= worldgen.TileTypeLava; tileType++ {
		count := counts[tileType]
		percentage := float64(count) / float64(total) * 100
		if count > 0 {
			fmt.Printf("  %-8s: %3d tiles (%5.1f%%)\n", worldgen.TileTypeString(tileType), count, percentage)
		}
	}
}
